<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/public/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>合同管理</title>
<% request.setAttribute("menu", 1); %>
<%@ include file="/WEB-INF/page/public/contentmeta.jsp"%>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="<%=basePath%>css/global.css" media="all" />
<link rel="stylesheet" href="<%=basePath%>plugins/font-awesome/css/font-awesome.min.css"/>
<link rel="stylesheet" href="<%=basePath%>css/system.css" media="all"/>
<link rel="stylesheet" href="<%=basePath%>css/tab.css" media="all" />

<style type="text/css">

#TM-layui-uphetonginfo,#TM-layui-addzhengshu,.collection-money,#TM-layui-pay {display: none;}
.layui-form-label i {color: red; padding-right: 3px;}

.uppzhide1,.uppzhide2 {display:none;}
.bianji{width:30px;height:30px;background:url(../images/sprite.png);background-position:-170px -174px;float:right;margin-left: 80px;}
.bianji1{width:30px;height:30px;background:url(../images/sprite.png);background-position:-170px -174px;float:right;}
.biancolor{width:70.5%;background-color:#f3f9fd;border:1px solid #e4e4e4;padding:20px 0 20px 0;margin-left:50px;]}
</style>

</head>
<body> 


<!-- 主展示页面开始 -->
<div id="TM-layui-hetong" >
	<div class="TM-he-tong admin-entering">
		
	<div class="biancolor">
		<div>
			<div class="form-left">
	            <div class="layui-form-item">
	                <label class="layui-form-label">单位名称 : </label>
	                <div class="layui-input-block">${info.customerInfo.cname}</div>
	            </div>
	            <div class="layui-form-item">
	                <label class="layui-form-label">服务费用 : </label>
	                <div class="layui-input-block"><fmt:formatNumber value="${info.servicecharge}" pattern="#,#00"/>元</div>       
			               
	            </div>
	            <div class="layui-form-item">
	                <label class="layui-form-label">合同签订时间 : </label>
	                <div class="layui-input-block">${info.signingtime.substring(0,10)}</div>
	            </div>
	            <div class="layui-form-item layui-form-text">
		            <label class="layui-form-label">合同备注 : </label>
		            <div class="layui-input-block">${info.remark}</div>  
	        	</div>
	        	<div class="layui-form-item">
	        		<label class="layui-form-label">企业合同文件 :</label>
	        		<div class="layui-input-block">
	        			<c:forEach var="fileobj" items="${info.fileList}" varStatus="f1">
	        				<span data="${fileobj.fileid}" uiddata="${info.customerInfo.uid}">
	        					<c:if test="${param.rol!=null&&param.rol==1}">
		            						<a style="margin: 0 10px 0 0; text-decoration: underline; color: #2591D0;"  href="/file/${fileobj.fileid}" title="${fileobj.remark}">文件${f1.index+1}</a>
	           					</c:if>
	           					<c:if test="${param.rol==null||param.rol!=1}">
	           						<c:if test="${info.customerInfo.uid == sessionScope.user.id}">
	          							 <a style="margin: 0 10px 0 0; text-decoration: underline; color: #2591D0;"  href="/file/${fileobj.fileid}" title="${fileobj.remark}">文件${f1.index+1}</a>
	          							</c:if>
	           					</c:if>
		            		</span>
	        			</c:forEach>
	        		</div>
	        	</div>             
        	</div>
        	<div class="form-right">
	            <div class="layui-form-item">
	                <label class="layui-form-label">合同金额 : </label>
	                <div class="layui-input-block" style="width:325px;float:left;margin-left:0px;">	              	                
		              <fmt:formatNumber value="${info.totalamount}" pattern="#,#00"/>元           
	                </div>
	            </div>
	            <div class="layui-form-item warehouse">
	                <label class="layui-form-label">合同类型: </label>
	                <div class="layui-input-block">
						<dic:cf type="1" name="contract_type" value="${info.contracttype}"/>
					</div>
	            </div> 
	            <div class="layui-form-item">
	            	<label class="layui-form-label">合同签订年限 : </label>
	                <div class="layui-input-block">
	                	<dic:cf type="1" name="life_type" value="${info.lifetype}"/>
	                </div>
	            </div>            
        	</div>
        	<div class="form-right">
        		<div class="bianji upcontent" data="${info.id}"></div>
        	</div>
		</div>
	  <c:set  property="rcjgtitle"  var="rcjgtitle" value="人才证书价格" /><c:set  property="qyjgtitle" var="qyjgtitle" value="企业证书价格" />
       <c:set  property="bzsm"  var="bzsm" value="备注" />	
         <c:set  property="rytitle"  var="rytitle" value="" />
	<div class="layui-form-item TM-hetong-zhengshu">
     		<label class="layui-form-label"><c:if test="${info.contracttype==0}"><c:set  property="rytitle"  var="rytitle" value="资质" /><c:set  property="rcjgtitle"  var="rcjgtitle" value="成本价" /><c:set  property="qyjgtitle" var="qyjgtitle" value="代办价格" /></c:if><c:if test="${info.contracttype==1}"><c:set  property="rytitle"  var="rytitle" value="猎证" /></c:if><c:if test="${info.contracttype==2}"><c:set  property="rytitle"  var="rytitle" value="培训" /><c:set  property="rcjgtitle"  var="rcjgtitle" value="单价" /><c:set  property="qyjgtitle" var="qyjgtitle" value="总价" /><c:set  property="bzsm"  var="bzsm" value="数量（本）" /></c:if> : </label>
	           <div class="layui-input-block">
	           	<c:forEach var="obj"  items="${info.sublist}" >
	     		       <div class="TM-hetong-block uppayment" data="${obj.id}" style="background-color:#fff;">
	     		       		<ul class="clefix">
			            		<li>${obj.customerInfo.cname}</li>
			            		<c:if test="${obj.isadditional==1}">
			            			 <li>其它费用:<span><fmt:formatNumber value="${obj.totalamount}" pattern="#,#00"/>元</span></li> 
			            		</c:if>
			            		<c:if test="${obj.isadditional==null||obj.isadditional==0}">
			            		 <li>${rcjgtitle}:<span><fmt:formatNumber value="${obj.totalamount}" pattern="#,#00"/>元</span></li>
			            		 <li>${qyjgtitle}:<span><fmt:formatNumber value="${obj.alonemoney}" pattern="#,#00"/>元</span></li>
			            		  <li>${bzsm}:<span>${obj.zsremark}</span></li>
			            		</c:if>
			            		<li>所属人:<span>${obj.createuserName}</span></li>
			            		<li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
			            		<!-- 只有在上传了人才合同之后，才显示人才合同文件 -->
			            		<li class="hetong-file-name">合同文件:
		            				<c:forEach var="fileobj" items="${obj.fileList}" varStatus="f1"> 
		            					<span data="${fileobj.fileid}" uiddata="${obj.customerInfo.uid}">
		            						<c:if test="${param.rol!=null&&param.rol==1}">
		            							  <a href="/file/${fileobj.fileid}" title="${fileobj.remark}">文件${f1.index+1}</a>
			            					</c:if>
			            					<c:if test="${param.rol==null||param.rol!=1}">
			            						<c:if test="${obj.customerInfo.uid == sessionScope.user.id}">
		            							  <a href="/file/${fileobj.fileid}" title="${fileobj.remark}">文件${f1.index+1}</a>
		            							</c:if>
			            					</c:if> 
		            					</span>
		            				</c:forEach>
			            		</li>
		            		</ul>
	     		       	</div>
	     		    </c:forEach> 
	           </div>
   		</div> 
   		
   	</div>	
		<div class="layui-form-item TM-hetong-jilu">
      		<label class="layui-form-label">回款记录: </label>
            <div class="layui-input-block">
            	<c:forEach  items="${info.mlList}"  var="ml">
            		 <div class="TM-hetong-block " >
	            		<%-- <span class="TM-jilu-date">${ml.updatedate.substring(0,10)}</span> --%>
	            		<p class="bianji1 upcollection" data="${ml.id}" appdata="${ml.approvalstatus}"></p>
	            		<c:if test="${ml.approvalstatus==1}">
	            			<!-- 待审批 -->
	            			<span class="TM-icondsp icon-stamp"></span>
	            		</c:if>
	            		<c:if test="${ml.approvalstatus==0}">
	            			<!-- 审批中 -->
	            			<span class="TM-icon icon-stamp"></span>
	            		</c:if>
	            		<c:if test="${ml.approvalstatus==2}">
	            			<!-- 审批通过 -->
	            			<span class="TM-iconytg icon-stamp"></span>
	            		</c:if>
	            		<c:if test="${ml.approvalstatus==3}">
	            			<!-- 驳回 -->
	            			<span class="TM-iconbh icon-stamp"></span>
	            		</c:if>
		            	<ul>
		            		<li>回款金额:${ml.totalamount}元(${ml.transfertype==0?"现金":"转账"})</li>
		            		<li>到帐时间:${ml.arrivaltime.substring(0,10)} </li>
							<li>收款方式:${ml.moneytype==0?"预付款":ml.moneytype==1?"全款":ml.moneytype==2?"中期款":"公示款"}</li>
							<li>收款账户:${ml.bankname}</li>
							<li>打款帐号或打款人:${ml.name}${ml.remark}</li>
							<li>
								<c:if test="${ml.voucher != null && ml.voucher.length() > 0 }">
									回款凭证:
									<c:forEach items="${ml.voucher.split(',')}" var="pzobj" varStatus="p1">
										<a class="showpz" data="${pzobj}">凭证${p1.index+1}</a>
									</c:forEach>
									<span class="TM-jilu-date">${ml.updatedate.substring(0,10)}</span>
								</c:if>
								<c:if test="${ml.voucher == null || ml.voucher.length() < 1 }">
									回款凭证:暂无凭证
								</c:if>
							</li>
		            	</ul>
	            	</div> 	
            	</c:forEach> 
            </div>
    	</div>
	</div>
</div>
<!-- 主展示页面结束 -->


<!-- 修改合同内容弹窗开始 -->
<div id="TM-layui-uphetonginfo">
	<div class="TM-he-tong admin-entering">
		<form class="layui-form TM-entering-form" action="" id="hetongform" novalidate="novalidate">
			<div class="form-left">
				<div class="layui-form-item">
					<label class="layui-form-label">企业名称 : </label>
					<div class="layui-input-block htqyname">${info.customerInfo.cname}</div>
					<input type="hidden" name="cusid" id="qyid" value="${info.customerInfo.id}">
					<input type="hidden" name="id" id="htid" value="${info.id}">
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><span>服务费用 :</span></label>
					<div class="layui-input-block">
						<input type="text" name="servicecharge" id="servicecharge" readonly="readonly" autocomplete="off" class="layui-input" value="${info.servicecharge}">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><i>*</i><span>签订时间 :</span> </label>
					<div class="layui-input-block">
						<input type="text" name="signingtime" id="signingtime" readonly="readonly" placeholder="yyyy-mm-dd" autocomplete="off"
							class="layui-input" onclick="layui.laydate({elem: this})" value="${info.signingtime.substring(0,10)}">
					</div>
				</div>
			</div>
			<div class="form-right">
				<div class="layui-form-item">
					<label class="layui-form-label"><i>*</i><span>合同金额 :</span></label>
					<div class="layui-input-block">
						<input type="text" name="totalamount" id="totalamount"
							readonly="readonly" autocomplete="off" class="layui-input" value="${info.totalamount}">
					</div>
				</div>
				<div class="layui-form-item warehouse">
					<label class="layui-form-label"><i>*</i><span>合同类型 :</span></label>
					<div class="layui-input-block">
						<select name="contracttype" lay-filter="contracttype">
							<dic:cf type="2" name="contract_type" value="${info.contracttype}" />
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><i>*</i><span>签订年限 :</span></label>
					<div class="layui-input-block">
						<select name="lifetype" lay-filter="lifetype">
							<dic:cf type="2" name="life_type" value="${info.lifetype}" />
						</select>
					</div>
				</div>
			</div>
			<div class="layui-form-item TM-hetong-jilu">
				<label class="layui-form-label">合同备注 :</label>
				<div class="layui-input-block">
					<textarea placeholder="请输入内容" name="remark" class="layui-textarea" >${info.remark}</textarea>
				</div>
			</div>
			<div class="layui-form-item TM-hetong-jilu">
				<label class="layui-form-label"><i>*</i><span>修改内容 :</span></label>
				<div class="layui-input-block">
					<textarea placeholder="请仔细输入修改内容,必填" name="modifyRecord" id="htmodifyRecord" class="layui-textarea" ></textarea>
				</div>
			</div>
			<div class="entering" id="sxzs" style="width: 95%">
				<h4>
					<font id="rytitle">${rytitle}</font>&nbsp;&nbsp;
					<button
						class="layui-btn layui-btn-primary layui-btn-small addlxr zhengshu"
						type="button">+添加人员</button>
				</h4>
				<table class="site-table table-hover TM-table3"
					style="border: 1px solid #FFFFFF">
					<thead>
						<tr>
							<th style="width: 8%;">客户名称</th>
								<th style="width: 35%;" id="rzjgtitle">${rcjgtitle}</th>
								<th style="width: 25%;"  id="qyjgtitle">${qyjgtitle}</th>
								<th style="width: 17%;" id="zssl">${bzsm}</th>
								<th style="width: 8%;">所属人</th>
								<th style="width: 8%;">操作</th>
						</tr>
					</thead>
					<tbody class="tb_zs">
						<c:forEach var="obj" items="${info.sublist}" varStatus="sbl">
							<!-- 判断一下,不要附加合同 -->
							<c:if test="${obj.isadditional != 1 }">
								<tr class="zs${obj.customerInfo.id}" data="${obj.customerInfo.id}">
									<td  >${obj.customerInfo.cname}</td>
									<td>
										<input type="text" value="${obj.totalamount}" name="totalms"  style="width:60px;height:25px;">&nbsp;<label>/元</label>  
										<!-- 判断是否有其他费用 -->
										<c:if test="${obj.othermoney != null && obj.othermoney > 0}">
											<span id="othermy${obj.id}">
												&nbsp;&nbsp;&nbsp;&nbsp;
												<label>其它费用:</label>
												<input type="text" value="${obj.othermoney}" name="otmoney" style="width:60px;height:25px;">&nbsp;
												<label>/元</label>
											<span>
										</c:if>
										<c:if test="${obj.othermoney == null || obj.othermoney < 1}">
											<span id="othermy${obj.id}" style="display:none;">
												&nbsp;&nbsp;&nbsp;&nbsp;
												<label>其它费用:</label>
												<input type="text" value="${obj.othermoney}" name="otmoney" style="width:60px;height:25px;">&nbsp;
												<label>/元</label>
											<span>
										</c:if>
										<input type="hidden"   name="uids" value="${obj.uid}">
										<input type="hidden" name="cids" value="${obj.customerInfo.id}">
										<input type="hidden" name="advancemoney" value="0">
									</td>
				                	<td><input type="text" value="${obj.alonemoney}" name="alonems"  style="width:60px;height:25px;">&nbsp;<label>/元</label></td>
				                	<td><input type="text" value="${obj.zsremark}" name="zsremark"  style="width:100%;height:25px;"></td>
				                	<td>${obj.createuserName}</td>
				                	<td>
										<div class="layui-btn-group">
											<button class="layui-btn layui-btn-primary layui-btn-small addothermoney"  data="${obj.id}" type="button">  <i class="layui-icon">&#xe654;</i>  </button>
											<button class="layui-btn layui-btn-primary layui-btn-small deletezs" data="${obj.customerInfo.id}" type="button">  <i class="layui-icon">&#xe640;</i>  </button>
			                            </div>
				                	</td>
								</tr>
							</c:if>
						</c:forEach>
					</tbody>
				</table>
			</div>
		</form>
	</div>
</div>
<!-- 修改合同内容弹窗结束 -->

<!-- 添加证书弹框开始 -->
<div id="TM-layui-addzhengshu">
	<div class="tab-condition" style="margin-left: 35px;">
		<form class="layui-form clefix" action="" id="zssearch">
			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="text" name="keyWord" id="zskeyword"
						autocomplete="off" placeholder="请输入关键字" class="layui-input">
					<input type="hidden" id="skpg" name="skipToPage" value="1">

				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<select name="state" class="" lay-filter="state">
						<option value="-1" selected="">成熟等级</option>
						<option value="0"
								<c:if test="${cuinfo.state==0 || state == 0}">selected</c:if>>最新资源</option>
						<option value="1"
							<c:if test="${cuinfo.state==1 || state == 1}">selected</c:if>>意向不明</option>
						<option value="2"
							<c:if test="${cuinfo.state==2 || state == 2}">selected</c:if>>意向明确</option>
						<option value="3"
							<c:if test="${cuinfo.state==3 || state == 3}">selected</c:if>>意向强烈</option>
						<option value="7"
							<c:if test="${cuinfo.state==7 || state == 7}">selected</c:if>>合作客户</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<button class="layui-btn TM-btn-search zssearchbtn" type="button">
					<i class="layui-icon layui-unselect layui-tab-close">&#xe615;</i>搜索
				</button>
			</div>
		</form>
	</div>
	<div class="entering">
		<table class="site-table table-hover TM-table3"
			style="width: 90%; margin: 0 auto;">
			<thead>
				<tr>
					    <th style="width: 102px;">是否垫款</th>
						<th style="width: 122px;">客户名称</th>
						<th style="width: 100px;">垫款总额</th>
						<th style="width: 172px;">身份证号</th>
						<th style="width: 172px;">所属人</th>
						<th style="width: 171px;">所在库</th>
						<th style="width: 101px;">操作</th>
				</tr>
			</thead>
			<tbody class="tb_customerzs">
			</tbody>
		</table>
		<div class="admin-table-page">
			<div id="zspage" class="page"></div>
		</div>
	</div>
</div>
<!-- 添加证书弹框结束 -->


<!-- 回款记录修改弹窗开始 -->
<div class="collection-money">
	<div class="TM-he-tong admin-entering">
		<form class="layui-form TM-entering-form" action="/customer/upskmoneylog" id="collectionform" method="post" novalidate="novalidate" enctype="multipart/form-data">
			<div class="form-left" style="width: 40%;">
				<div class="layui-form-item">
	                <label class="layui-form-label">收款金额 : </label>
	                <div class="layui-input-inline" style="width:100px">
	                	<input type="text" class="layui-input" id="sk_totalamount" name="totalamount">
	                </div>
	                <div class="layui-form-mid layui-word-aux">合同总金额(<span id="skhtzje"></span>)</div>
            	</div>
            	<div class="layui-form-item">
	                <label class="layui-form-label">收款方式 : </label>
	                <div class="layui-input-block" >
	                	<select name="moneytype" id="sk_moneytype" lay-filter="moneytype">
	                		<option value="0">预付款</option>
	                		<option value="2">中期款</option>
	                		<option value="3">公示款</option>
	                		<option value="1">全款</option>
	                	</select>
	                </div>
            	</div>
            	<div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i>打款户名 : </label>
	                <div class="layui-input-block" >
	                	<input type="text" id="sk_compaccount" name="name" class="layui-input"    >
	                </div>
            	</div>
			</div>
			<div class="form-right" style="margin-left: 40px;">
				<div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i>到帐时间 : </label>
	                <div class="layui-input-block" >
	                	<input type="text" id="sk_arrivaltime" name="arrivaltime" class="layui-input" readonly="readonly" placeholder="yyyy-mm-dd" autocomplete="off" onclick="layui.laydate({elem: this})">
	                </div>
            	</div>
            	<div class="layui-form-item">
	                <label class="layui-form-label">类型 : </label>
	                <div class="layui-input-block" >
	                	<select name="transfertype" id="sk_transfertype" lay-filter="transfertype"> 
	                		<option value="1">转账</option>
	                		<option value="0">现金</option>
	                	</select>
	                </div>
            	</div>
            	<div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i>收款账户 : </label>
	                <div class="layui-input-block" >
	                	<select name="bankname" id="sk_myaccount"  lay-filter="myaccount"> 
	                	    <option value="">收款账户</option>
	                		 <dic:cf type="2" name="bank_name" value="" />

	                	</select>
	                </div>
            	</div>
			</div>
			<div class="layui-form-item TM-hetong-jilu">
	      		<label class="layui-form-label">打款备注 : </label>
	            <div class="layui-input-block">
	      			<textarea placeholder="请输入内容" name="remark" id="sk_remark" autocomplete="off" class="layui-textarea"></textarea>
	    		</div>
     		</div>
     		<div class="layui-form-item TM-hetong-jilu">
	      		<label class="layui-form-label"><i>*</i>修改内容 : </label>
	            <div class="layui-input-block">
	      			<textarea placeholder="请详细输入修改内容,必填" name="modifyRecord" id="sk_modifyRecord" autocomplete="off" class="layui-textarea"></textarea>
	    		</div>
     		</div>
			
			<!-- 凭证上传开始 -->     		
     		<div>
     			<div class="layui-form-item TM-hetong-jilu">
	     			<label class="layui-form-label">上传凭证1 : </label>
	     			<div class="layui-input-block" >
		            	<input type="file" class="layui-input" name="file" id="pzfile1" style="width: 40%"> 
		            	<span class="addpz" adddata="1" showdata="2">添加凭证</span>
		            </div>
     			</div>
     		
	     		<div class="layui-form-item TM-hetong-jilu uppzhide1">
	     			<label class="layui-form-label">上传凭证2 : </label>
	     			<div class="layui-input-block" >
		            	<input type="file" class="layui-input" name="file" id="pzfile2" style="width: 30%">
		            	<span class="addpz" adddata="2" showdata="3">添加凭证</span>
		            </div>
	     		</div>
     		
	     		<div class="layui-form-item TM-hetong-jilu uppzhide2">
	     			<label class="layui-form-label">上传凭证3 : </label>
	     			<div class="layui-input-block" >
		            	<input type="file" class="layui-input" name="file" id="pzfile3" style="width: 30%">
		            </div>
	     		</div>
     		</div>
     		<!-- 凭证上传结束 -->
			     		
     		<%-- <input name="skipToPage" id="skipToPage"  type="hidden" value="${pager.pageNo}">
			<input type="hidden" id="pageNo" name="pageNo" value="${pager.pageNo}">
			<input type="hidden" id="totalPage" name="totalPage" value="${pager.totalPages}"> --%>
     		<input type="hidden" name="contractid" class="contractid" value="">
     		<input type="hidden" name="cusid" class="cusid" value="">
     		<input type="hidden" name="type"   value="1">
     		<input type="hidden" name="id" id="sk_id" value=""> 
		</form>
	</div>
</div>
<!-- 回款记录弹窗结束 -->

<script type="text/javascript">

layui.use(['laytpl','form','laydate','laypage','form'], function() {
    var $ = layui.jquery,
            layer = layui.layer,
            laytpl = layui.laytpl,
            laypage = layui.laypage;
    var form = layui.form();
    var tjstate =0;
    
     layer.tips('点击修改合同', '.upcontent', {
    	  tips: [1, '#1E9FFF'],
    	  tipsMore: true,
    	  time: 4000
    	});
     
     layer.tips('点击修改回款记录', '.upcollection', {
   	  tips: [1, '#1E9FFF'],
   	tipsMore: true,
   	  time: 4000
   	});
     
    
    //点击修改合同信息
    $(".upcontent").on("click",function(){
    	
    	document.getElementById("hetongform").reset();
    	
    	//获取合同id
    	var id = $(this).attr("data");
    	var type = 1;
    	//判断是否有修改记录
    	$.ajax({
    		type : "post",
    		data : {id : id,type : type},
    		url : "/customer/checkhistoryisexist",
    		dataType : "json",
    		async : false,
    		success : function(data){
    			if (data > 0) {
    				//说明有记录
    				layer.msg("有未审批的修改记录,请等待审批完成后,再次申请",{icon: 2});
    			} else {
    				layer.open({
    		    		title:'修改合同详情',
    		       		type:1,
    		        	content:$('#TM-layui-uphetonginfo'),
    				    shadeClose:true,
    				    scrollbar:true,
    				    btnAlign:'c',
    				    btn: ['提交修改', '取消'],
    				    area:['99%','99%'],
    				    yes: function(){
    				    	if (tjstate == 0) {
    				    		if (CalculatedPrice()){
    				    			$("#hetongform").submit();
    				    		}
    				    	} else {
    				    		layer.msg("正在提交合同,请勿重复提交",{icon: 0});
    				    	}
    				    },
    				    success: function(layero, index){
    				    	tjstate =0;
    				    }
    				});
    			}
    		}
    	});
    });
    
    //动态修改合同金额和服务费用
    //只要改变了人才证书价格,其他费用,企业证书价格,都要重新计算合同合同金额和服务费用
    //人才
    $(document).on("blur","input[name=totalms]",function(){
    	CalculatedPrice();
    });
    //其他
	$(document).on("blur","input[name=otmoney]",function(){
		CalculatedPrice();
    });
    //企业
	$(document).on("blur","input[name=alonems]",function(){
		CalculatedPrice();
	});
    
    //计算服务费用和合同总金额,并验证数据是否符合标准
    var CalculatedPrice = function(){
    	
    	var result =true;
    	
    	var trs = $(".tb_zs tr");
    	var resallcount = 0; //人才证书总价
		var cusallcount = 0; //企业证书总价
		var othallcount = 0; //其他价格总价
		
		//判断是否已添加证书
		if(trs.length<1){ //判断是否已添加证书
			 layer.tips("请选择证书", $("#sxzs"), {
				 tips: [1,tipColor],
				 tipsMore: true
			 });
			 return false;
		 }
		
		var inputobj = trs.find("input[name=totalms]"); //人才
		var inputobj2 = trs.find("input[name=alonems]"); //企业
		var inputobj3 = trs.find("input[name=otmoney]"); //其他
		
		for(var i=0;i<inputobj.length;i++){
			 //判断证书价格是否已填
			 var val = $(inputobj[i]).val();
			 if(val.length<1){
				 layer.tips("请填写人才证书价格", $(inputobj[i]), {
					 tips: [2,tipColor],
					 tipsMore: true
				 });
				 result = false;
			 }else{
				 var reg = /^[0-9]*$/;
				 if (!reg.test(val)) { 
					 layer.tips("价格请填写数字", $(inputobj[i]), {
						 tips: [2,tipColor],
						 tipsMore: true
					 });
					 result = false;
 				}else{
 					resallcount += parseInt(val);
 				}
 			}
 			
 		}
		for(var i=0;i<inputobj2.length;i++){
			  //判断证书价格是否已填
			var val = $(inputobj2[i]).val();
			if(val.length<1){
				 layer.tips("请填写企业证书价格", $(inputobj2[i]), {
  				 tips: [2,tipColor],
         	     		 tipsMore: true
         	     	 });
				result = false;
			}else{
				var reg = /^[0-9]*$/;
				if (!reg.test(val)) { 
					layer.tips("价格请填写数字", $(inputobj2[i]), {
     				 tips: [2,tipColor],
          	     		 tipsMore: true
          	     	 });
					result = false;
				} else {
					cusallcount += parseInt(val);
				}
			} 
		}
		for (var i = 0;i < inputobj3.length;i ++) {
  			var val = $(inputobj3[i]).val();
  			var reg = /^[0-9]*$/;
  			if (!reg.test(val)) {
  				layer.tips("价格请填写数字", $(inputobj2[i]),{
  					tips: [2,tipColor],
  					tipsMore: true
  				});
  				result = false;
  			} else if (val.length > 0) {
  				othallcount += parseInt(val);
  			}
  		}
		if(cusallcount<(resallcount+othallcount)){
			layer.tips("人才证书价格不能大于企业证书价格", $("#sxzs"), {
				tips: [1,tipColor],
				tipsMore: true
			});
			result = false;
		}else{
			//服务费用=企业-人才-其他
			$("#servicecharge").val(cusallcount-resallcount-othallcount);
			//合同总价=企业
			$("#totalamount").val(cusallcount);
		}
		
		return result;
		
    }
    
    //点击添加证书
	$(".zhengshu").on("click",function(){
		zsadd = layer.confirm('确定要新增证书吗？', {
    		btn: ['确定','取消']
    	},function(){
    		layer.close(zsadd);
    		zspop = layer.open({
    			title:'添加证书',
    			type:1,
    			id:"tjzs",
    			shadeClose: true,
    			content:$('#TM-layui-addzhengshu'),
    			btnAlign:'c',
    			area:['90%','95%']
    		});
		}, function(){});
	});
    
	//证书搜索
	$(".zssearchbtn").on("click",function(){
		
		var kd =  $.trim($("#zskeyword").val());
		$("#skpg").val(1);
		if(kd.length<1){
			layer.tips("请输入关键字", "#zskeyword", {
				tips: [1,'#f7625e'], 
				time:5000,
     		    tipsMore: false
     		});
			return false;
		}else{
			$("#zskeyword").val(kd);
		    var values = $("#zssearch").serialize()
			var result = getZsUser(values);
		    var getTpl = $("#zslb").html();
			
			laytpl(getTpl).render(result, function(html){
				$(".tb_customerzs").html(html);
			});
			
			laypage({
				cont: 'zspage',
				curr: 1,//'${pager.pageNo}'
				pages: result.totalPages,//'${pager.totalPages}' //总页数
          		groups: 5, //连续显示分页数
				skip: true,
				jump: function(obj, first) {
					//得到了当前页，用于向服务端请求对应数据
					var curr = obj.curr;
					if(!first) {
						$("#skpg").val(curr);
                   		values = $("#zssearch").serialize()
              			result = getZsUser(values); 
                   		var getTpl = $("#zslb").html();
                    	laytpl(getTpl).render(result, function(html){
            				$(".tb_customerzs").html(html);
            			}); 
					}
				}
			});  
		}
	});
	
	//添加搜索出来的证书
	$(document).on("click",'.addzs',function(){
		
		var result = eval('(' + $(this).attr("data") + ')');
		var getTpl = $("#zs").html();
		
		if($(".tb_zs  tr[data="+result.id+"]").length>0){
			layer.msg('请勿重复添加' ,{icon: 0});
			return false;
		}
		
		laytpl(getTpl).render(result, function(html){
			$(".tb_zs").append(html);
			layer.close(zspop);
		});
		
	});
    
    //点击删除证书
    $(document).on("click",".deletezs",function(){
    	
    	var id = $(this).attr("data");
    	layer.confirm('确定要删除该证书吗？', {
    		btn: ['确定','取消'] //按钮
    	},function(){
			$(".zs"+id).remove(); 
			layer.msg("删除成功",{icon:1 });
		}, function(){});
    });
    
    
    //点击添加或取消其他价格
    $(document).on("click",".addothermoney",function(){
    	var id = $(this).attr("data");
    	$("#othermy"+id).toggle();
		$("#othermy"+id +"  input[name=otmoney]").val(0);
    });
    
	 var rzjgtitle ="人才证书价格";
	 var qyjgtitle ="企业证书价格";
	 var zssl="备注";
	 var rytitle="猎证";
	 form.on('select(contracttype)', function(data){
		    if(data.value==0){
		       //资质合同	
		    	 rzjgtitle ="成本价格";
		    	 qyjgtitle ="代办价格";
		    	 rytitle="资质";
		    	 zssl="备注";
		    }else  if(data.value==1){
		    	//猎证合同 
		    	 rzjgtitle ="人才证书价格";
		    	 qyjgtitle ="企业证书价格";
		    	 rytitle="猎证";
		    	 zssl="备注";
		    }else if (data.value==2){
		    	//培训合同
		    	 rzjgtitle ="单价";
		    	 qyjgtitle ="总价";
		    	 rytitle="培训";
		    	 zssl="数量（本）";
		    }
		    $("#rzjgtitle").html(rzjgtitle);
	    	 $("#qyjgtitle").html(qyjgtitle);
	    	 $("#zssl").html(zssl);
	    	 $("#rytitle").html(rytitle);
		});
	 
    
    //合同验证表单
    $("#hetongform").validate({
		rules: {
			signingtime : {
	    		required:true
			},
	    	totalamount : {
	    		required:true,
	    		digits:true
	    	},
			contracttype : {
	    		required:true
	    	},
	    	lifetype : {
	    		required:true
	    	},
	    	modifyRecord : {
	    		required:true
	    	}
	    },
	    messages: {
	   		signingtime : {
	   			required:"请选择合同签订时间"
	   		},
	   		totalamount : {
	   			required:"请填写合同金额",
	   			digits:"请填写正确金额"
	   		},
	   		contracttype : {
	   			required:"请选择合同类型"
	   		},
	   		lifetype : {
	   			required:"请选择合同签订年限"
	   		},
	   		modifyRecord : {
	    		required:"请输入修改内容"
	    	}
	   	},
	   	errorPlacement: function(error, element){
    		tjstate =0;
			layer.tips(error.text(), element, {
				tips: [2,tipColor],
     		 tipsMore: true
     		});
   		},
   		submitHandler: function(formobj){
   			
   			if (CalculatedPrice()){
   				tjstate =1;
   				var values = $("#hetongform").serialize();
   				$.ajax({
   					type : "post",
   					url : "/customer/savecontentupdate",
   					data : values,
   					dataType : "json",
     		 		async : false,
     		 		success : function(data){
     		 			if (data == 1) {
     		 				layer.closeAll();
     		 				layer.msg('修改合同申请成功', {icon: 1});
     		 			} else {
     		 				layer.msg('修改合同申请失败', {icon: 2});
     		 			}
     		 		}
   				});
   				
   				
   			}
   		}
    });
    
    //修改回款记录
    $(document).on("click",".upcollection",function(){
    	var id = $(this).attr("data");
    	var appdata = $(this).attr("appdata");
    	if (appdata == 2) {
    		$.ajax({
        		type : "post",
        		url : "/customer/getmoneylogbyid",
        		data : {id:id},
        		dataType : "json",
        		async : false,
        		success : function(data){
        			
        			$("#sk_totalamount").val(data.totalamount);
        			$("#skhtzje").text(data.contractInfo.totalamount);
        			$("#sk_moneytype").val(data.moneytype);
        			$("#sk_compaccount").val(data.name);
        			$("#sk_arrivaltime").val(data.arrivaltime);
        			$("#sk_transfertype").val(data.transfertype);
        			$("#sk_myaccount").val(data.bankname);
        			$("#sk_remark").val(data.remark);
        			
        			form.render();
        			
        			var id = data.id;
        			var cusid = data.cusid;
        			var contractid = data.contractid;
        			
        			var compaccount = $("#sk_compaccount").val();
        			var myaccount = $("#sk_myaccount").val();
        			
        			
        			//在这里判断是否有未通过审批的记录
        			var type = 2;
        			$.ajax({
        				type : "post",
        				data : {id : id,type : type},
        				url : "/customer/checkhistoryisexist",
        	    		dataType : "json",
        	    		async : false,
        	    		success : function(data){
        	    			if (data > 0) {
        	    				//说明有记录
        	    				layer.msg("有未审批的修改记录,请等待审批完成后,再次申请",{icon: 2});
        	    			} else {
        	    				layer.open({
        	        	    		title:'修改收款记录',
        	        	       		type:1,
        	        	        	content:$('.collection-money'),
        	        			    shadeClose:true,
        	        			    scrollbar:true,
        	        			    btnAlign:'c',
        	        			    btn: ['提交修改', '取消'],
        	        			    area:['99%','99%'],
        	        			    yes: function(){
        	        			    	if (tjstate == 0){
        	        			    		$(".contractid").val(contractid);
        	        			    		$(".cusid").val(cusid);
        	        			    		if (validatorCollecttin()){
        	        			    			tjstate = 1;
        	        			    			var remark = $("#remark").val(); 
        	        			    			//$("#remark").val("打款账户："+compaccount+ "     收款账户："+myaccount+"    \r\n"+remark);
        	        			    			var values = $("#collectionform").serialize();
        	        			    			$("#sk_id").val(id);
        	        			    			$("#collectionform").submit();
        	        			    		}
        	        			    	}
        	        			    }, 
        	        			    success: function(layero, index){
        	        			    	tjstate =0;
        	        			    }
        	        			});
        	    			}
        	    		}
        			});
        		}
        	});
    	} else {
    		layer.msg('只能修改已通过审批的回款记录', {icon: 2});
    	}
    });
    
    //点击添加凭证
    $(".addpz").on("click",function(){
    	var adddata = $(this).attr("adddata");
       	var showdata = $(this).attr("showdata");
        $(".uppzhide"+adddata).show();
        $(this).hide();
	});
    
    var validatorCollecttin = function(tamount){
    	var totalamount = $.trim($("#sk_totalamount").val());
    	var arrivaltime = $("#sk_arrivaltime").val();
    	var compaccount = $("#sk_compaccount").val();
    	var myaccount = $("#sk_myaccount").val();
    	var remark = $("#sk_remark").val();
    	var modifyRecord = $("#sk_modifyRecord").val();
    	//var pzfile1 = $("#pzfile1").val();
    	/* if (pzfile1 == null || pzfile1 == "") {
    		layer.tips("请上传收款凭证",$("#pzfile1"),{
    			tips: [2,tipColor],
    			tipsMore: true
    		});
    		return false;
    	} */
    	if (totalamount == null || totalamount.length < 1) {
    		layer.tips("请输入总收款金额", $("#totalamount"), {
					tips: [2,tipColor],
 	     		 tipsMore: true
 	     		});
    		return false;
    	}else{
    		
    		var reg = /^[0-9]*$/;
        	if (!reg.test(totalamount)) {
    			layer.tips("总收款金额请填写数字", $("#sk_totalamount"), {
 					tips: [2,tipColor],
     	     		tipsMore: true
     	     	});
    			return false;
       		}
    		
    	   var money = totalamount -tamount;
    	   if(money>0){
    		   layer.tips("输入金额已超过合同金额"+money, $("#sk_totalamount"), {
					tips: [2,tipColor],
    	     		 tipsMore: true
    	     		});
    	   }
    	}
    	if (arrivaltime == null || arrivaltime.length < 1) {
    		layer.tips("请输入到帐时间", $("#sk_arrivaltime"), {
					tips: [2,tipColor],
 	     		 tipsMore: true
 	     		});
    		return false;
    	}
    	if (compaccount == null || compaccount.length < 1) {
    		layer.tips("请输入到打款账户", $("#sk_compaccount"), {
					tips: [2,tipColor],
 	     		 tipsMore: true
 	     		});
    		return false;
    	}
    	if (myaccount == null || myaccount.length < 1) {
    		
    		layer.tips("请选择收款账户",$("#sk_myaccount").parent().find("input"), {
					tips: [2,tipColor],
 	     		 tipsMore: true
 	     		});
    		return false;
    	}
    	if (modifyRecord == null || modifyRecord.length < 1) {
    		layer.tips("请输入修改内容", $("#sk_modifyRecord"), {
				tips: [2,tipColor],
	     		 tipsMore: true
	     	});
			return false;
    	}
    	
    	return true;
    }
    
    
    //根据条件搜索证书列表
    getZsUser = function (o){
    	var result ="";
    	var values = o;
    	$.ajax({
    		type : "post",
    		url : "/customer/userlist",
    		data : values,
    		async:false,
    		dataType : "json",
    		success : function(data){
    			result = data;
    		}
    	});
    	return result;
    }
    
});
	
</script>

<!-- 模版开始 -->
<!-- 证书列表模版 -->
<script id="zslb" type="text/html"> 
	{{#  layui.each(d.resultList, function(index, item){ }} 
		<tr  >
			<td>{{# if(item.advancemoney>0){ }}<span style="color:red;">已垫款</span> {{#  } else { }} 未垫款 {{#  } }} </td>
			<td>{{item.cname}}</td>
			<td>{{item.advancemoney}}</td>
			<td>{{item.idcard}}</td>
			<td>{{item.createusersname}}</td>
			<td>{{# if(item.state==1){ }} 意向不明 {{#  } }} {{#  if(item.state==7){ }} 合作客户 {{#  } }}{{#  if(item.state==2){ }} 意向明确{{#  } }}{{#  if(item.state==3){ }} 意向强烈{{#  } }}{{#  if(item.state==0){ }} 最新资源{{#  } }}</td>
			<td>
				<button class="layui-btn layui-btn-primary layui-btn-small addzs" data="{'id':'{{item.id}}','uid':'{{item.uid}}','name':'{{item.cname}}','createname':'{{item.createusersname}}','advancemoney':'{{item.advancemoney}}'}"   type="button">添加<i class="layui-icon"></i></button>
			</td>
		</tr>
	{{#  }); }}  
</script>
<!-- 证书模版 -->
<script id="zs" type="text/html"> 
	<tr class="zs{{d.id}}" data="{{d.id}}">
		<td  >{{d.name}}</td>
		<td><input type="text" value="{{d.advancemoney}}" name="totalms"  style="width:60px;height:25px;">&nbsp;<label>/元</label>  <span id="othermy{{d.id}}"  style="display:none">&nbsp;&nbsp;&nbsp;&nbsp;<label>其它费用:</label><input type="text" value="0" name="otmoney"  style="width:60px;height:25px;">&nbsp;<label>/元</label><span>   <input type="hidden"   name="uids" value="{{d.uid}}"  > <input type="hidden"   name="cids" value="{{d.id}}"  ><input type="hidden"   name="advancemoney" value="{{d.advancemoney}}"  ></td>
		<td><input type="text" value="" name="alonems"  style="width:60px;height:25px;">&nbsp;<label>/元</label></td>
	    <td><input type="text" value="" name="zsremark"  style="width:100%;height:25px;"></td>		
        <td>{{d.createname}}</td>
		<td>
			<div class="layui-btn-group">
				<button class="layui-btn layui-btn-primary layui-btn-small addothermoney"  data="{{d.id}}" type="button">  <i class="layui-icon">&#xe654;</i>  </button>
				<button class="layui-btn layui-btn-primary layui-btn-small deletezs" data="{{d.id}}" type="button">  <i class="layui-icon">&#xe640;</i>  </button>
			</div>
		</td>
	</tr>	
</script>

</body>
</html>